package com.websuites.utils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

import com.websuites.core.Constant;
import com.websuites.core.response.WsHttpServletResponse;

@SuppressWarnings("unchecked")
public class ProgressUtil 
{
	public static void ShowError(WsHttpServletResponse response, HashMap mapParam, int nPercent) throws IOException
	{
		List<HashMap<String,String>> listRows = new ArrayList<HashMap<String,String>>();
		HashMap<String,String> mapRow = new LinkedHashMap<String,String>();
		mapRow.put("returncode", "1");
		mapRow.put("returnmsg", "-");
		listRows.add(mapRow);
		response.send(mapParam, listRows);
		response.getWriter().flush();		
	}

	public static void ShowPrecent(WsHttpServletResponse response, HashMap mapParam, int nPercent) throws IOException
	{
		List<HashMap<String,String>> listRows = new ArrayList<HashMap<String,String>>();
		HashMap<String,String> mapRow = new LinkedHashMap<String,String>();
		mapRow.put("returncode", "2");
		mapRow.put("type", Constant.PERCENT_TYPE_PERCENT);
		mapRow.put("code", (new Integer(0)).toString());
		mapRow.put("color", (new Integer(Constant.MSG_COLOR_MSG)).toString());
		mapRow.put("percent", (new Integer(nPercent)).toString());
		mapRow.put("returnmsg", "-");
		listRows.add(mapRow);
		response.send(mapParam, listRows);
	}
	
	public static void ShowInfo_Title(WsHttpServletResponse response, HashMap mapParam, String sErrorMsg) throws IOException
	{
		List<HashMap<String,String>> listRows = new ArrayList<HashMap<String,String>>();
		HashMap<String,String> mapRow = new LinkedHashMap<String,String>();
		mapRow.put("returncode", "2");
		mapRow.put("type", Constant.PERCENT_TYPE_MESSAGE);
		mapRow.put("code", (new Integer(Constant.MSG_CODE_TITLE)).toString());
		mapRow.put("color", (new Integer(Constant.MSG_COLOR_MSG)).toString());
		mapRow.put("percent", (new Integer(0)).toString());
		mapRow.put("returnmsg", sErrorMsg);
		listRows.add(mapRow);
		response.send(mapParam, listRows);
	}
	
	public static void ShowInfo_Warning(WsHttpServletResponse response, HashMap mapParam, String sErrorMsg) throws IOException
	{
		List<HashMap<String,String>> listRows = new ArrayList<HashMap<String,String>>();
		HashMap<String,String> mapRow = new LinkedHashMap<String,String>();
		mapRow.put("returncode", "2");
		mapRow.put("type", Constant.PERCENT_TYPE_MESSAGE);
		mapRow.put("code", (new Integer(Constant.MSG_CODE_TITLEWAR)).toString());
		mapRow.put("color", (new Integer(Constant.MSG_COLOR_WAR)).toString());
		mapRow.put("percent", (new Integer(0)).toString());
		mapRow.put("returnmsg", sErrorMsg);
		listRows.add(mapRow);
		response.send(mapParam, listRows);	
	}

	public static void ShowInfo_Detail(WsHttpServletResponse response, HashMap mapParam, String sErrorMsg) throws IOException
	{
		List<HashMap<String,String>> listRows = new ArrayList<HashMap<String,String>>();
		HashMap<String,String> mapRow = new LinkedHashMap<String,String>();
		mapRow.put("returncode", "2");
		mapRow.put("type", Constant.PERCENT_TYPE_MESSAGE);
		mapRow.put("code", (new Integer(Constant.MSG_CODE_DETAIL)).toString());
		mapRow.put("color", (new Integer(Constant.MSG_COLOR_MSG)).toString());
		mapRow.put("percent", (new Integer(0)).toString());
		mapRow.put("returnmsg", sErrorMsg);
		listRows.add(mapRow);
		response.send(mapParam, listRows);
	}
	
	public static void ShowError_Title(WsHttpServletResponse response, HashMap mapParam, String sErrorMsg) throws IOException
	{
		List<HashMap<String,String>> listRows = new ArrayList<HashMap<String,String>>();
		HashMap<String,String> mapRow = new LinkedHashMap<String,String>();
		mapRow.put("returncode", "2");
		mapRow.put("type", Constant.PERCENT_TYPE_MESSAGE);
		mapRow.put("code", (new Integer(Constant.MSG_CODE_TITLEERR)).toString());
		mapRow.put("color", (new Integer(Constant.MSG_COLOR_ERR)).toString());
		mapRow.put("percent", (new Integer(0)).toString());
		mapRow.put("returnmsg", sErrorMsg);
		listRows.add(mapRow);
		response.send(mapParam, listRows);
	}
	
	public static void ShowError_Detail(WsHttpServletResponse response, HashMap mapParam, String sErrorMsg) throws IOException
	{
		List<HashMap<String,String>> listRows = new ArrayList<HashMap<String,String>>();
		HashMap<String,String> mapRow = new LinkedHashMap<String,String>();
		mapRow.put("returncode", "2");
		mapRow.put("type", Constant.PERCENT_TYPE_MESSAGE);
		mapRow.put("code", (new Integer(Constant.MSG_CODE_DETAILERR)).toString());
		mapRow.put("color", (new Integer(Constant.MSG_COLOR_ERR)).toString());
		mapRow.put("percent", (new Integer(0)).toString());
		mapRow.put("returnmsg", sErrorMsg);
		listRows.add(mapRow);
		response.send(mapParam, listRows);
	}
}
